mui.previewImage(); //图片预览

mui.init({
	//下拉刷新
	pullRefresh: {
		container: "#refreshContainer", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
		up: {
			height: 50, // 可选.默认50.触发上拉加载拖动距离
			auto: true, // 可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...", // 可选，正在加载状态时，上拉加载控件上显示的标题内容
			contentnomore: '没有更多的数据了', // 可选，请求完毕若没有更多数据时显示的提醒内容；
			callback: pullupRefresh //加载数据方法 
		}
	}
});
/*
 * 获取本地信息
 */

/*var pagesize = 10; //每页条数
var number = 0; //页数
var isOver = false; //是否加载完  */

function getList() {
	var user_id = localStorage.getItem("user_id");
	var number = $("#number").val(); //页数
	interfRequest.my_label_opus.data = {
		user_id: user_id,
		number: number,
		pagesize: 5
	}
	socialRequest(interfRequest.my_label_opus);
}
//我的--标志方法
function my_label_opusHandle(data) {
	if(data.error_code == 10000) {
		//console.log('我的标记==》' + JSON.stringify(data))
		/*var total = data.data.totalElements / number; //總頁數 
		if(number > total) { //当前的页数
			isOver = true;
			mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
		}
		if(number = total) { //当前的页数
			isOver = true;
			mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
		}*/
		var user_id = localStorage.getItem("user_id");
		var number = $("#number").val(); //页数
		var html='<div class="no_dynamic_box" style="text-align: center; color:#ACACB4;margin-top:60%;font-size: 16px;">你还没有标记的对象哦~快去标记吧！</div>';
		if(number == 0) {
			if(!data.data){ 
				$(".mui-content").html(html);
			}else if(data.data.content.length == 0) { 
				$(".mui-content").html(html);
			} else {
				my_label_opus_data(data); //数据处理
			}
		} else {
			if(data.data.content.length == 0) {
				$("#isOver").val(true);
				mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
			} else {
				my_label_opus_data(data); //数据处理
			}
		}

	} else {
		mui.alert(data.msg);
	}
}

//数据处理
function my_label_opus_data(data) {
	var isOver = $("#isOver").val();
	if(isOver == "false") {
		var number = $("#number").val(); //页数
		var ye = Number(number) + Number(1);
		$("#number").val(ye++);
		mui('#refreshContainer').pullRefresh().endPullupToRefresh(true); //停止正在加载
		mui('#refreshContainer').pullRefresh().enablePullupToRefresh(); //显示上拉加载文字
	} else {
		$("#isOver").val(true);
		mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
	}
	var html = "";
	for(var i = 0; i < data.data.content.length; i++) {
		var dynamic_type = data.data.content[i].dynamic_type; //发布类型
		var arr_img = data.data.content[i].dynamic_file; //图片数组
		var img_arr = arr_img.split(","); //图片
		var is_valid = data.data.content[i].praise //点赞
		var head_img_url = data.data.content[i].head_img_url;
		html += '<li class="mui-table-view-cell mui-media my_dynamic_after">';
		html += '<a href="javascript:;">';
		if(!head_img_url){
			html += '<img class="mui-media-object mui-pull-left" src="../../images/log.png">';
		}else{
			html += '<img class="mui-media-object mui-pull-left" src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].head_img_url + '">';
		}
		html += '<div class="mui-media-body">';
		html += '<span class="my_dynamic_name">' + data.data.content[i].nickname + '</span>';
		html += '<p class="mui-ellipsis mui_ellipsi">' + data.data.content[i].release_time + '</p>';
		html += '</div>';
		html += '</a>';
		html += '<p class="my_dynamic_video_txt">' + data.data.content[i].content + '</p>';
		html += '</li>';
		if(dynamic_type == 1) { //视频
			html += '<li class="mui-table-view-cell mui-media my_dynamic_video">'; 
			html += '<div class="video_center" style="position: relative;">';
			html += '<video name="media" width="100%" height="220px"   poster="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].dynamic_file + '?spm=a2c4g.11186623.2.1.yjOb8V&x-oss-process=video/snapshot,t_1000,m_fast">' ;  //  视频封面';
			html += '<source src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].dynamic_file + '"/>';
			html += '</video>';  
			html += '<div class="img_video"><img src="../../images/ship.png" ></div>';
			html += '</div>';
			//html += '<p class="my_dynamic_video_txt">' + data.data.content[i].content + '</p>';
			html += '</li>';
		} else if(dynamic_type == 2) { //图片
			if(arr_img != "") {
				html += '<li class="mui-table-view-cell mui-media my_dynamic_listtu">';
				html += '<ul class="mui-row my_dynamic_recomm">';
				for(var j = 0; j < img_arr.length; j++) { //循环图片					
					if(img_arr.length == 1) {
						html += '<li class="mui-col-sm-8 mui-col-xs-8"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></li>';
					} else if(img_arr.length == 2 || img_arr.length == 4) {
						html += '<li class="mui-col-sm-6 mui-col-xs-6"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></li>';
					} else if(img_arr.length = 3) {
						html += '<li class="mui-col-sm-4 mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></li>';
					} else if(img_arr.length > 4) {
						html += '<li class="mui-col-sm-4 mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></li>';
					}
				}
				html += '</ul>';
				html += '</li>';
			}
		}
		html += '<ul class="mui-table-view my_dynamic_con follow_list">';
		html += '<li class="mui-table-view-cell">';
		html += '<p class="mui-row iconfont my_dynamic_row">';
		if(is_valid == 1) { //点赞
			html += '<a class="mui-col-sm-4 mui-col-xs-4" href="javascript:;"><span class="icon-xin icon-xins my_dynamic_xin"></span>&nbsp;' + data.data.content[i].praise + '</a>';
		} else {
			html += '<a class="mui-col-sm-4 mui-col-xs-4" href="javascript:;"><span class="icon-xin icon-xins"></span>&nbsp;' + data.data.content[i].praise + '</a>';
		}
		html += '<a class="mui-col-sm-4 mui-col-xs-4" href="javascript:;"><span class="icon-navicon-dxgl"></span>&nbsp;' + data.data.content[i].comment_number + '</a>';
		html += '<a class="mui-col-sm-4 mui-col-xs-4" href="javascript:;"><span class="mui-icon mui-icon-bars"></span></a>';
		html += '</p>';
		html += '</li>';
		html += '</ul>';
	}
	$("#my_sign_list").append(html);

	//图片大小处理
	var width4 = $(".my_dynamic_recomm .mui-col-xs-4").width();
	$(".my_dynamic_recomm .mui-col-xs-4").height(width4);
	var width6 = $(".my_dynamic_recomm .mui-col-xs-6").width();
	$(".my_dynamic_recomm .mui-col-xs-6").height(width6);
}

//下拉加载
function pullupRefresh() {
	setTimeout(function() {
		mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
		setTimeout(function() {
			var isOver = $("#isOver").val();
			mui('#refreshContainer').pullRefresh().endPullupToRefresh((isOver)); //参数为true代表没有更多数据了。  
			getList(); //ajax   
		}, 500);
	}, 500);
}
 
//视频播放
mui('body').on('tap', '.img_video', function() {
	var videoMedia = $(this).siblings().children("source").attr("src");
	var bu = document.getElementById("videoMedia"); 
	bu.src = videoMedia;
	bu.play();  
	$(".video_ji").show();   
}); 

//关闭视频
mui('body').on('tap', '.back', function() {
	$(".video_ji").hide();
	var bu = document.getElementById("videoMedia");
	bu.innerHTML = '';
	bu.pause();
});
